//============================================================================
// Name        : webserver.cpp
// Author      : Hari Krishnan
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>
#include <string>
#include "Queue.h"
#include "pthread.h"

using namespace std;

class webserver {

	queue dqueue;
	queue rqueue;
	string filename;


	public:

	void setFileName(string filenamer){
		filename=filenamer;
	}


	void dispatcher(void){
		cout<<"we dispatcher are called";
		ifstream in ("webserver_input.txt");
				while(in)
				{
					std::string line;
					std::getline(in,line);
					cout<<"request queued"<<line<<endl;
					dqueue.enqueue(line);

				}
	}
	void resolver(void)
	{
		cout<<"I am resolver thread!";

	}
	void stop(){
		pthread_exit(NULL);
	}


};
void* dispatcher_helper(void *arg){
	static_cast<webserver*>(arg)->dispatcher();
}
int main() {
	pthread_t tid;
	pthread_attr_t attr;
	int rc;
	webserver web;
	web.setFileName("webserver_input.txt");
	pthread_attr_init(&attr);
	rc=pthread_create(&tid,&attr,dispatcher_helper,&web);
	if(rc){
		printf("ERROR; return code from pthread_create() is %d\n", rc);
		    exit(-1);
	}
	for(int i=0;i<50;i++){
			cout << "!!!Hello World!!!" <<i<< endl;
		}
	pthread_exit(NULL);




//	queue q;
//	q.enqueue("hari");
//	q.show();
//	q.enqueue("Krishnan");
//	q.show();
//	q.dequeue();
//	q.show();
//	q.dequeue();
//	q.show();

	 // prints !!!Hello World!!!
	return 0;
}
